//
//  MeatOrderPriceCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/8/24.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatOrderPriceCell.h"

@implementation MeatOrderPriceCell

#pragma mark - lifecycle methods

- (void)setupUI{
    
    [self addSubview:self.titleLab1];
    [self addSubview:self.titleLab2];
    [self addSubview:self.detailLab1];
    [self addSubview:self.detailLab2];
}

- (void)setupLayout{
    
    CGFloat width = (KScreenWidth - 30)/2.0;
    {
        _titleLab1.size = _titleLab2.size = _detailLab1.size = _detailLab2.size = CGSizeMake(width, 18);
        _titleLab1.mj_x = _titleLab2.mj_x = 15;
        _titleLab1.mj_y = 15;
        _titleLab2.mj_y = _titleLab1.bottom + 10;
        
        _detailLab1.mj_x = _detailLab2.mj_x = (KScreenWidth - 30 )- width - 15;
        _detailLab1.mj_y = _titleLab1.mj_y;
        _detailLab2.mj_y = _titleLab2.mj_y;
    }
    
}



#pragma mark - setter methods

- (void)setItem:(MeatPayOrderItem *)item{
    
    __block float price = 0;
    [item.meets enumerateObjectsUsingBlock:^(Meats * _Nonnull meats, NSUInteger idx, BOOL * _Nonnull stop) {
        [meats.list enumerateObjectsUsingBlock:^(MeatsItem * _Nonnull obj, NSUInteger index, BOOL * _Nonnull stop) {
            price += [obj.nowPrice floatValue];
        }];
    }];
    
    _detailLab1.text = [NSString stringWithFormat:@"¥%.2f", price];
}


#pragma mark - getter methods

- (UILabel *)titleLab1{
    
    if (!_titleLab1) {
        _titleLab1 = [UILabel makeLabelWithText:@"商品金额" textColor:UIColorFromRGB(0x454545) font:mFont(13) textAliment:0];
    }
    return _titleLab1;
}

- (UILabel *)titleLab2{
    
    if (!_titleLab2) {
        _titleLab2 = [UILabel makeLabelWithText:@"运费" textColor:UIColorFromRGB(0x454545) font:mFont(13) textAliment:0];
    }
    return _titleLab2;
}


- (UILabel *)detailLab1{
    
    if (!_detailLab1) {
        _detailLab1 = [UILabel makeLabelWithText:@"976.23" textColor:UIColorFromRGB(0xF25C62) font:mFont(12) textAliment:2];
    }
    return _detailLab1;
}

- (UILabel *)detailLab2{
    
    if (!_detailLab2) {
        _detailLab2 = [UILabel makeLabelWithText:@"0" textColor:UIColorFromRGB(0xF25C62) font:mFont(12) textAliment:2];
    }
    return _detailLab2;
}


@end
